package jp.sourceforge.akjrcp.util;

import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.WorkbenchWindow;

public class StatusBarUtils {

	public static void showStatusBar(String messages){
		showStatusBar(messages,false);//should i sync is default?
	}
	public static void showStatusBar(String messages,boolean sync){
		if(sync)
			PlatformUI.getWorkbench().getDisplay().syncExec(new ShowStatusBar(messages));
		else
			PlatformUI.getWorkbench().getDisplay().asyncExec(new ShowStatusBar(messages));
	}
	
	public static class ShowStatusBar implements Runnable{
		private String message;
		
		public ShowStatusBar(String message){
			this.message=message;
		}
		
		public void run(){
			WorkbenchWindow workbenchWindow =  (WorkbenchWindow) PlatformUI.getWorkbench().getWorkbenchWindows()[0];
			IActionBars actionBars = workbenchWindow.getActionBars();
			IStatusLineManager manager = actionBars.getStatusLineManager();
			manager.setMessage(message);
		
		}
	}

}
